let includes = ([
    "include/common.js",
]);

function onMessage(agent, pto) {

    os.debug("123123123123");
    os.debug(agent);
    os.debug(pto);
    os.debug(pto.getType());
    os.debug(OProtocol.LOGIN.getT());
    let user;
    if (pto.getType() == OProtocol.LOGIN.getT()) {

        let str = pto.getContent();

        let s2 = str.split(",");
        if ( s2.length < 2 ) {
            let data = {
                protype: 1,
                data: "名称格式不对哦！",
            }
            os.tellObject(agent, os.stringify(data));
            return;
        }
        //查找有没有玩家存在
        let loginUser = getUser(s2[0]);
        if (!objectp(loginUser)) {
            //允许登录
            user = os.create("clone/user.js");
            os.debug(user, "打印一下user!!");
            user.set("agent", agent);
            user.set("account", s2[0]);
            os.tellObject(agent, "新用户登录！");

        } else {

            os.debug("玩家在世界中!");
            user = loginUser;
            user.set("agent", agent);
            os.tellObject(agent, "在线的用户更换连接！");
        }
        return;
    }

    // //非登录协议 就是执行指令了，传回给JAVA，让JAVA调用其他JS处理
    // os.callCmd(user,pto);

    return {};
}

